package cn.yuxiaoyuan.controller;

import cn.yuxiaoyuan.article.doamin.Article;
import cn.yuxiaoyuan.article.doamin.ArticleType;
import cn.yuxiaoyuan.article.query.ArticleQuery;
import cn.yuxiaoyuan.article.query.ArticleTypeQuery;
import cn.yuxiaoyuan.common.util.R;
import cn.yuxiaoyuan.service.IArticleService;
import cn.yuxiaoyuan.service.IArticleTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @author solargen
 * @version 1.0
 * @date 2025/5/11 10:37
 */
@Api(value = "文章类型相关的接口")
@RestController
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    private IArticleService articleService;

    @GetMapping("/{id}")
    public R findById(@PathVariable("id")Long id){
        return R.ok(articleService.findById(id));
    }

    @ApiOperation(value = "查询全部用户信息")
    @GetMapping
    public R findAll(){
        return R.ok(articleService.findAll());
    }

    @DeleteMapping("/{id}")
    public R deleteById(@PathVariable("id")Long id){
        articleService.deleteById(id);
        return R.ok();
    }
    @PostMapping("/deleteAll")
    public R batchDelete(@RequestBody List<Long> ids){
        articleService.batchDelete(ids);
        return R.ok();
    }

    @PostMapping
    public R add(@RequestBody Article article){
        if(article.getId() == null){
            articleService.add(article);
        }else {
            articleService.update(article);
        }
        return R.ok();
    }

    @PostMapping("/list")
    public R pageList(@RequestBody ArticleQuery articleQuery){
        return articleService.pageList(articleQuery);
    }

    @GetMapping("/test")
    public R test(){
        return R.ok(articleService.place());
    }
}
